<?php

namespace App\Http\Resources\NewWebSite;

use App\model\Workshop;
use Illuminate\Http\Resources\Json\ResourceCollection;

class WorkshopCollection extends ResourceCollection
{
    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {

        return [
            'code'=>0,
            'data'=>$this->collection->map(function($item){
                if($item->type==0){
                    $price=$item->rent!=0 ? $item->rent.Workshop::RENT  : '面议';
                }else{
                    $price=$item->price!=0 ? $item->rent.Workshop::SALE  : '面议';
                }
                return [
                    'workshop_id'=>$item->id,
                    'logo'=>$item->logo.Workshop::LOGO,
                    'title'=>$item->title,
                    'types'=>$item->industry->reject(function($item,$key){
                        return $key>1;
                    }),
                    'type'=>$item->type,
                    'area'=>$item->area,
                    'park_name'=>$item->park->title ?? '',
                    'price'=>$price,
                    'tags'=>$item->tags->reject(function($item,$key){
                        return $key>2;
                    }),
                    'qu'=>$item->qu->title ?? ''
                ];
            })
        ];
    }
}
